<?php


namespace App\Admin\Forms;

use App\Models\MaterialUnit;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class Music extends Form implements LazyRenderable
{
    use LazyWidget;

    public function handle(array $input)
    {
        $key = $this->payload['key'];
        MaterialUnit::find($key)->update($input);
        return $this->response()->success('保存成功')->refresh();
    }

    public function form()
    {
        $key = $this->payload['key'] ?? null;
        $unit = MaterialUnit::find($key);
        if ($unit->music_id == 0) {
            $this->select('music_id', '音乐')
                ->options([1=>'aa',2=>'bb'])
                ->required();
        } else {
            $this->select('music_id', '音乐')
                ->options([1=>'aa',2=>'bb'])->value($unit->music_id)
                ->required();
        }
    }
}
